package com.trkj.service.cf;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspPage;
import javax.servlet.jsp.PageContext;

import org.apache.jasper.servlet.JspServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.cf.DefinetissueDAO;
import com.trkj.pojo.Organization;
import com.trkj.pojo.OrganizationStructure;
import com.trkj.service.ServiceException;

@Service
@Transactional(rollbackFor=Exception.class)
public class DefinetissueService {
	@Autowired
	private DefinetissueDAO definetissueDAO;

	public long pageCount() {
		return definetissueDAO.count();
	}

	// 分页 定义组织
	public List<Organization> Page(Integer page, Integer rows) throws ServiceException {
		try {
			List<Organization> list = definetissueDAO.queryByPage(new PageRequest(page - 1, rows));
			return list;
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

	// 搜索
	public List<Organization> filedByName(String organiName) throws ServiceException {
		try {
			return definetissueDAO.queryByOrgareaName("%" + organiName + "%");
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

	// 新增
	public void definetissueupdate(String organiName, String organiRemarks, String strings) throws ServiceException {
		System.out.println(organiName + " " + organiRemarks);
		// Object sessions= session.getAttribute("staff");

		// System.out.println(sessions+" efsdf");
		try {
			Date date = new Date();
			Organization o = new Organization();
			// o.setOrganiId(organsId);
			o.setOrganiName(organiName == null ? "1" : organiName);
			o.setOrganiRemarks(organiRemarks == null ? "暂无详情" : organiRemarks);
			o.setOrganiTime(new Timestamp(date.getTime()));
			o.setOrganiPerson(strings);
			definetissueDAO.save(o);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

	// 删除
	public void definetissueremove(Long organiId) {
		definetissueDAO.delete(organiId);
	}

	// 编辑
	public void definetissueupdate(Long organiId, String organiName, String organiRemarks) throws ServiceException {
		try {
			Organization or = definetissueDAO.findOne(organiId);
			Date date = new Date();
			or.setOrganiId(organiId);
			or.setOrganiName(organiName);
			or.setOrganiRemarks(organiRemarks);
			or.setOrganiEndtime(new Timestamp(date.getTime()));
			definetissueDAO.save(or);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

}
